#! /usr/bin/env python
# -*- coding: utf8 -*-

# Alexandre Coster <acoster@rhrk.uni-kl.de>
# AG DBIS - Technische Universität Kaiserslautern

# mXML: Messy XML Generator
# This application generates a dirty (messy) XML file (with changes
# both on the values and the structure) based on a "clean" input

import sys
import random
import zope.interface

import base

if __name__ == "__main__":
    print "You shouldn't be running this file!"
    sys.exit()

class delWords(object):
    zope.interface.implements(base.IAlgorithm)
    name = "delWords"
    
    def __init__(self, node):
        if node.find("./parameters/allowEmpty") != None and node.find("./parameters/allowEmpty").text.strip() == 'False':
            self.__allow_empty = False
        else:
            self.__allow_empty = True

    def __call__(self, string):
        words = string.split(" ")

        if not self.__allow_empty and len(words) == 1:
            return string

        position = random.randint(0, len(words) - 1)

        return " ".join(words[:position] + words[position + 1:])

__plugins__ = (delWords,)
